var uid;
document.addEventListener('plusready',function(event){
	uid = plus.storage.getItem('uid');
	//在线问诊状态
	$.ajax({
		type :"get",
		url :apiRoot+"?m=home&c=member&a=onStatus&uid="+uid,
		dataType :'json',
		success :function(data){
			console.log(JSON.stringify(data));
			if(data.video == '1')$('#video').addClass('mui-active');
			if(data.online == '1')$('#online').addClass('mui-active');
			//遍历开关集合
			$('.mui-switch').each(function(index ,value){
				var field = $(this).attr('id');
				//判断每种开关的状态	   
				$(this).on('tap' , function(){
					//获取点击后的状态
					var isActive = document.getElementById(field).classList.contains("mui-active");
					if(isActive){
						var line = '1';
					}else{
						var line = '0';
					}
					//改变问诊状态
					$.ajax({
						type:"get",
						url:apiRoot+"?m=home&c=member&a=changeStatus",
						data :{
							uid :uid,
							field :field,
							line :line
						},
						dataType :'json',
						success :function(data){
							console.log(JSON.stringify(data));
							plus.nativeUI.closeWaiting();
							if(data > 0){
								if(isActive){
									toast('开启成功');
								}else{
									toast('关闭成功'); 
								}
							}else{
								toast('修改失败');
							}
						},
						error :function(e){
							console.log(JSON.stringify(e));
							errortoast();
						}
					});
				})
			})
		},
		error :function(e){
			console.log(JSON.stringify(e));
			errortoast();
		}
	});
	//点击在线交流判断是否能点进交流页
	$('.zailine').on('tap',function(){
		if($('#online').hasClass('mui-active')){
			goNewPage('free-information-text-list.html');
		}
	})
	$('.videoline').on('tap',function(){
		if($('#video').hasClass('mui-active')){
			goNewPage('free-information-video-list.html');
		}
	})
},false)
